import type { Directive } from 'vue'

//创建一个自定义鉴权指令
const hasPermission = (permissions: string[]) => {
  if (!permissions.length) return true
  const userStore = useUserStore()
  return userStore.userInfo?.permissions.some(permission =>
    permissions.includes(permission),
  )
}

export const auth: Directive = {
  mounted(el, binding) {
    if (!hasPermission(binding.value)) {
      el.parentNode?.removeChild(el)
    }
  },
}
